package com.yoomiito.app.widget.dialog;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.yoomiito.app.R;

public class ShareBottomDialog_1 extends BaseDialog implements View.OnClickListener {

    private OnShareItemClickListener mOnShareItemClickListener;
    private LinearLayout mSavePicLl;
    private boolean mShowSavePic = true;
    public ShareBottomDialog_1(@NonNull Context context) {
        this(context,0);
    }

    public ShareBottomDialog_1(@NonNull Context context, int themeResId) {
        super(context, R.style.dialog_2);
    }

    protected ShareBottomDialog_1(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    public View setView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_share,null);
        view.findViewById(R.id.item_share_wx).setOnClickListener(this);
        view.findViewById(R.id.item_share_dynamic).setOnClickListener(this);
        mSavePicLl = view.findViewById(R.id.item_share_photo);
        mSavePicLl.setOnClickListener(this);
        showSavePic(mShowSavePic);
        view.findViewById(R.id.cancel).setOnClickListener(this);
        setCanceledOnTouchOutside(true);
        setmGravity(Gravity.BOTTOM);
        setWidthPercent(1);
        return view;
    }

    @Override
    public void onClick(View v) {
        int i = 0;
        switch (v.getId()){
            case R.id.item_share_wx:
                i = 1;
                break;
            case R.id.item_share_dynamic:
                i = 2;
                break;
            case R.id.item_share_photo:
                i = 3;
                break;
            case R.id.cancel:
                dismiss();
                return;
        }
        if (mOnShareItemClickListener!=null){
            mOnShareItemClickListener.onClick(i);
        }
    }

    public void showSavePic(boolean show){
        mShowSavePic = show;
        if (mSavePicLl!=null){
            mSavePicLl.setVisibility(show?View.VISIBLE:View.GONE);
        }
    }

    public void setOnShareItemClickListener(OnShareItemClickListener onShareItemClickListener) {
        mOnShareItemClickListener = onShareItemClickListener;
    }

    public interface OnShareItemClickListener{
        void onClick(int type);
    }
}
